package com.xrit.sunnyday.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.xrit.sunnyday.dao.MemberDao;
import com.xrit.sunnyday.pojo.Member;
import com.xrit.sunnyday.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

/**
 * 手机登录 会员
 */
@Service(interfaceClass = MemberService.class)
public class MemberServiceImpl implements MemberService{

    @Autowired
    private MemberDao memberDao;
    /**
     * 通过手机号码查询会员信息
     *
     * @param telephone
     * @return
     */
    @Override
    public List<Member> findByTelephone(String telephone) {
        return memberDao.findByTelephone(telephone);
    }

    /**
     * 添加会员
     *
     * @param member
     */
    @Override
    public void add(Member member) {
        memberDao.add(member);
    }

    /**
     * 统计过去一年的会员总数
     *
     * @param months
     */
    @Override
    public List<Integer> getMemberReport(List<String> months) {
        //返回需要List<Integer>
        List<Integer> memberCount = new ArrayList<>();
        //循环12次 每个月查询一次
        for (String month : months) {
            String data = month + "-01" ;
            //拿过去一年的月份查截至本月的会员注册数量
            Integer count = memberDao.findMemberCountBeforeDate(data);
            memberCount.add(count);
        }
        return memberCount;
    }
}
